USE [NANS21V]
GO

/****** オブジェクト: SqlProcedure [dbo].[TeamKyogi] スクリプト日付: 2014/05/02 17:32:14 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TeamKyogi]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[TeamKyogi];
GO

CREATE PROCEDURE [dbo].[TeamKyogi]
	@TAIKAINO int,
	@SYUMOKUKUBUN_A int,
	@SYUMOKUKUBUN_B int
AS
SELECT 
	KYOGINO, 
	KYOGIMEI, 
	KIROKUKUBUN, 
	GATTAIFLG 
FROM 
	TBL_KYOGI AS K, 
	TBL_SYUMOKU_MASTER AS SM, 
	TBL_SYUBETU AS SB 
WHERE 
	K.SYUMOKUNO = SM.SYUMOKUNO 
	AND K.TAIKAINO = @TAIKAINO 
	AND K.SYUBETUNO = SB.SYUBETUNO 
	AND K.GATTAIFLG <> 2 
	AND SM.SYUMOKUKUBUN 
	IN 
	(@SYUMOKUKUBUN_A,@SYUMOKUKUBUN_B) 
ORDER BY
	 K.SEIBETUNO, SB.PRINTNO, SM.PRINTNO